// $Id$
// Licensed under Apache License Version 2.0
// See: http://www.apache.org/licenses/LICENSE-2.0.html
package de.servicezombie.tcmdb.rest.vo;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import de.servicezombie.lang.ReflectionUtils;

/**
 * Utilitiy base class for objects returned by a webservice
 * 
 * @author ChKa
 * @param <DO>
 *            derivated class
 */
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class AbstractWsDomainObject<DO> {

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}

	@Override
	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}

	@Override
	public boolean equals(Object other) {
		return EqualsBuilder.reflectionEquals(this, other, false);
	}

	/**
	 * read source and save its value into this object. uses all field
	 * annotated with {@link XmlElement}
	 * 
	 * @see java.lang.Object.clone()
	 */
	public void clone(DO source) {
		ReflectionUtils.cloneByAnnotatedField(source, this, XmlElement.class);
	}

}
